package cn.edu.scau.cmi.zhouxinyue.composite;

import java.util.ArrayList;

public class Composite extends Component{
	private int Pnumber=0;
	private int Tnumber=0;
	private int JudgeLeaf=0;
	private String name;
	private Component parent=null;
	private ArrayList<Leaf> allPerson=new ArrayList<>();
	private ArrayList<Component> allTeam=new ArrayList<>();
	
	public int JudgeLeaf() {
		return JudgeLeaf;
	}
	
	public Composite(String name,Component parent) {
		this.name=name;
		this.parent=parent;
	}

	@Override
	public Component getParent() {
		// TODO Auto-generated method stub
		return parent;
	}
	public String getName() {
		return name;
	}

	@Override
	public Component addPerson(Leaf person) {
		allPerson.add(person);
		Pnumber++;
		return parent;
	}

	@Override
	public Component addTeam(Component team) {
		allTeam.add(team);
		Tnumber++;
		return parent;
	}

	@Override
	public Component deletePerson(Leaf person) {
		int judge=0;
		for(int i=0;i<allPerson.size();i++) {
			if(person.getName().equals(allPerson.get(i).getName())) {
				judge=1;
				allPerson.remove(i);
				break;
			}
		}
		if(judge==1) {
			Pnumber--;
		}
		return parent;
	}

	@Override
	public Component deleteTeam(Component team) {
		int judge=0;
		for(int i=0;i<allTeam.size();i++) {
			if(team.getName().equals(allTeam.get(i).getName())) {
				judge=1;
				allTeam.remove(i);
				break;
			}
		}
		if(judge==1) {
			Tnumber--;
		}
		return parent;
	}

	@Override
	public ArrayList<Leaf> getPerson() {
		return allPerson;
	}

	@Override
	public ArrayList<Component> getTeam() {
		return allTeam;
	}
	
	public int getPnumber() {
		return Pnumber;
	}
	
	public int getTnumber() {
		return Tnumber;
	}

}
